/*
 * Copyright 2006-2008 Michele Mostarda ( michele.mostarda@gmail.com ).
 * All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the 'License');
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an 'AS IS' BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.graphnav.swing;

import java.awt.Graphics2D;
import java.awt.geom.Rectangle2D;

/**
 * Represents any shape into the {@link org.graphnav.swing.GraphPanel}
 * that can be moved.
 */
public abstract class MovableShape extends AbstractRenderable {

    /**
     * Returns the shape bounds.
     *
     * @param detailLevel
     * @return
     */
    public abstract Rectangle2D getBounds2D(int detailLevel);

    /**
     * Actuates the shape motion of a relative delta x / y.
     *
     * @param dx
     * @param dy
     */
    public abstract void move(int dx, int dy);

    /**
     * Sets the shape location to a specific point.
     * @param x
     * @param y
     */
    public abstract void setLocation(int x, int y);

    public Graphics2D getGraphics2D(Graphics2D g2d, int detailLevel) {
        Rectangle2D bounds = getBounds2D(detailLevel);
        Graphics2D clipped =  super.getGraphics2D(g2d);
        clipped.setClip((int) bounds.getX(), (int) bounds.getY(), (int) bounds.getWidth() + 1, (int) bounds.getHeight()  + 1);
        return clipped;
    }

}
